{include file="public/toper" /}
<div class="layui-tab layui-tab-brief main-tab-container">
    <ul class="layui-tab-title main-tab-title">
        <span class="main-tab-item">留言管理</span>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show" style="min-height: 500px">
            <!--搜索开始-->
            <form class="layui-form layui-form-pane search-form " method="get">
                <div class="layui-form-item">
                    <label class="layui-form-label">选择模型</label>
                    <div class="layui-input-inline">
                        <select name="models">
                            {volist name="$models" id="mo"}
                                {if condition="$mo['id'] neq 4"}
                                    <option value="{$mo.id}" {if condition="$models_id eq $mo['id']"} selected {/if}>{$mo.name}</option>
                                {/if}

                            {/volist}
                        </select>
                    </div>
                    <label class="layui-form-label">文章标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="search" value="{$search|default=''}"  placeholder="请输入文章标题搜索" autocomplete="off" class="layui-input">
                    </div>
                    <button class="layui-btn layui-btn-normal layui-form-item" lay-submit="" lay-filter="">搜索</button>
                </div>
                <div class="layui-btn layui-btn-danger layui-form-item up_comment"style="float: right">
                    留言数据修复
                </div>


            </form>
            <!--搜索结束-->
            <form class="layui-form" >

                <table class="list-table">
                    <thead>
                    <tr>

                        <th>ID</th>
                        <th>所属栏目</th>
                        <th>文章标题</th>
                        <th>
                            内容
                        </th>
                        <th class="can_click">
                            留言时间
                        </th>
                        <th style="text-align: center;" class="can_click">
                            留言QQ
                        </th>
                        <th style="text-align: center;" class="can_click">
                            留言IP
                        </th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        {notempty name="data['data']"}
                            {foreach name="data['data']" id="da"}
                                <tr>

                                    <td>{$da['id']}</td>
                                    <td>{$da['category_name']}</td>
                                    <td>{$da['title']}</td>
                                    <td>
                                        {if condition="strlen($da['content']) > 50"}
                                            {:mb_substr($da['content'],0,50)}...&nbsp;<span class="layui-btn layui-btn-xs comment_content" data-data="{:htmlspecialchars($da.content)}">查看</span>
                                        {else /}
                                         {$da['content']}
                                        {/if}
                                    </td>
                                    <td>{$da['create_time']}</td>
                                    <td style="text-align: center;">
                                        {:json_decode($da['send'],true)['qq']}
                                    </td>
                                    <td>
                                        {$da['ip']}
                                    </td>
                                    <td style="text-align: center;">
                                        <a class="layui-btn layui-btn-sm layui-btn-danger del_btn" article-id="{$da.id}" title="删除"  data-reply="{$da.reply}"><i class="layui-icon"></i></a>
                                    </td>
                                </tr>
                            {/foreach}
                        {/notempty}
                    </tbody>
                    <thead>
                        <tr>
                            <th colspan="3">
                            </th>
                            <th colspan="6"><div id="page">{$page}</div></th>
                        </tr>
                    </thead>

                </table>
            </form>

        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use(['element', 'layer', 'form' ,'upload' ,'laypage'], function(){
        var element = layui.element
                ,jq = layui.$
                ,form = layui.form
                ,laypage = layui.laypage
                ,upload = layui.upload;
        //ajax删除单个内容
        jq('.del_btn').click(function(){
            var reply = jq(this).data('reply');
            var name='此评论';
            if(reply != 0){
                name='此评论及下的' + reply + '条回复'
            }
            var id = jq(this).attr('article-id');
            layer.confirm('确定删除【'+name+'】?', function(index){
                loading = layer.load(2, {
                    shade: [0.2,'#000'] //0.2透明度的白色背景
                });
                jq.post(
                    '{:url("isDel")}',
                    {'id':id},
                    function(data){
                        if(data.code == 200){
                            layer.close(loading);
                            layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                location.reload();//do something
                            });
                        }else{
                            layer.close(loading);
                            layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                        }
                    }).error(function () {
                        layer.close(loading);
                        layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                });

            });

        });
        //全选
        form.on('checkbox(checkAll)', function(data){
            if(data.elem.checked){
                jq("input[type='checkbox']").prop('checked',true);
            }else{
                jq("input[type='checkbox']").prop('checked',false);
            }
            form.render('checkbox');
        });
        //选择一个
        form.on('checkbox(checkOne)', function(data){
            var is_check = true;
            if(data.elem.checked){
                jq("input[lay-filter='checkOne']").each(function(){
                    if(!jq(this).prop('checked')){ is_check = false; }
                });
                if(is_check){
                    jq("input[lay-filter='checkAll']").prop('checked',true);
                }
            }else{
                jq("input[lay-filter='checkAll']").prop('checked',false);
            }
            form.render('checkbox');
        });
        jq('.up_comment').click(function () {
            loading = layer.load(2, {
                shade: [0.2,'#000'] //0.2透明度的白色背景
            });
            jq.ajax({
                'url':"{:url('upComment')}",
                'type':'get',
                success:function (data) {
                    layer.close(loading);
                    if(data.code == 200){
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.reload();//do something
                        });
                    }else{
                        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                    }
                },
                error:function () {
                    layer.close(loading);
                    layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                }
            });
            layer.close(loading);
        });

        jq('.comment_content').click(function () {

            var data=jq(this).data('data');
            layer.alert(data);
            //console.log(data);
        })



    });

</script>
</body>
</html>